if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spFdsNCompleteFeed]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spFdsNCompleteFeed]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/***************************************************************************
* Name:			spFdsNStartFeed
* Purpose:		Used to complete an instance of a feed
*
*
* PARAMETERS
* Name					Description					
* -------------			-----------------------------------------------------------
* @_FeedInstanceId	
* @_FeedStatusTypeId	
*
* ERRORS USED		Description
* -------------		-----------------------------------------------------
* n/a
*
* RETURN VALUE
* Value    			Description					
* --------------	------------------------------------------------------
*	0				Succeeded
*	1				Failed
***************************************************************************/

CREATE PROCEDURE dbo.spFdsNCompleteFeed (
	@_FeedInstanceId integer 
	,@_FeedStatusTypeId integer
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @FEED_SUCCESS	Integer
	Set @FEED_SUCCESS = 2
	DECLARE @FEED_FAILED	Integer
	Set @FEED_FAILED = 3

	/*
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	The feed status can only be set to failed or success, otherwise stop here
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	If @_FeedStatusTypeId <> @FEED_FAILED and @_FeedStatusTypeId <> @FEED_SUCCESS
		return 1

	/*
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	Complete the feed
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	*/
	Update
		SvcFeedRun
	Set
		SvcFeedStatusTypeId = @_FeedStatusTypeId
		,EndDate = getdate()
	Where
		[Id] = @_FeedInstanceId

	SET NOCOUNT OFF

	return 0

END
GO

/******************************************************************
* CHANGE HISTORY
* $History: spFdsNStartFeed.sql $
-- 
*
******************************************************************/

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

